// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_COMMON_MEDIA_MEDIA_DEVICES_MOJOM_H_
#define CONTENT_COMMON_MEDIA_MEDIA_DEVICES_MOJOM_H_

#include <stdint.h>

#include <limits>
#include <type_traits>
#include <utility>

#include "base/callback.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/i18n/rtl.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "base/unguessable_token.h"
#include "base/values.h"
#include "base/version.h"
#include "cc/input/selection.h"
#include "cc/output/begin_frame_args.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/compositor_frame_metadata.h"
#include "cc/output/filter_operation.h"
#include "cc/output/filter_operations.h"
#include "cc/quads/draw_quad.h"
#include "cc/quads/render_pass.h"
#include "cc/quads/shared_quad_state.h"
#include "cc/resources/returned_resource.h"
#include "cc/resources/transferable_resource.h"
#include "cc/surfaces/frame_sink_id.h"
#include "cc/surfaces/local_frame_id.h"
#include "cc/surfaces/surface_id.h"
#include "cc/surfaces/surface_info.h"
#include "cc/surfaces/surface_reference.h"
#include "cc/surfaces/surface_sequence.h"
#include "content/common/bluetooth/web_bluetooth_device_id.h"
#include "content/common/content_export.h"
#include "content/common/frame_owner_properties.h"
#include "content/common/frame_replication_state.h"
#include "content/common/indexed_db/indexed_db_key.h"
#include "content/common/indexed_db/indexed_db_key_path.h"
#include "content/common/indexed_db/indexed_db_key_range.h"
#include "content/common/indexed_db/indexed_db_metadata.h"
#include "content/common/media/media_devices.h"
#include "content/common/media/media_devices.mojom-shared.h"
#include "content/common/resize_params.h"
#include "content/common/resource_request.h"
#include "content/common/resource_request_completion_status.h"
#include "content/common/service_worker/embedded_worker_start_params.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "content/common/service_worker/service_worker_types.h"
#include "content/public/common/media_metadata.h"
#include "content/public/common/push_event_payload.h"
#include "content/public/common/referrer.h"
#include "content/public/common/renderer_preferences.h"
#include "content/public/common/resource_response.h"
#include "content/public/common/web_preferences.h"
#include "device/bluetooth/bluetooth_uuid.h"
#include "gpu/command_buffer/common/capabilities.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/mailbox_holder.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "gpu/command_buffer/service/gpu_preferences.h"
#include "gpu/config/dx_diag_node.h"
#include "gpu/config/gpu_info.h"
#include "gpu/ipc/common/surface_handle.h"
#include "media/base/audio_codecs.h"
#include "media/base/audio_parameters.h"
#include "media/base/buffering_state.h"
#include "media/base/cdm_key_information.h"
#include "media/base/cdm_promise.h"
#include "media/base/channel_layout.h"
#include "media/base/content_decryption_module.h"
#include "media/base/decode_status.h"
#include "media/base/decryptor.h"
#include "media/base/demuxer_stream.h"
#include "media/base/eme_constants.h"
#include "media/base/encryption_scheme.h"
#include "media/base/pipeline_status.h"
#include "media/base/sample_format.h"
#include "media/base/subsample_entry.h"
#include "media/base/video_codecs.h"
#include "media/base/video_types.h"
#include "media/capture/video/video_capture_device_descriptor.h"
#include "media/capture/video_capture_types.h"
#include "mojo/public/cpp/bindings/associated_interface_ptr.h"
#include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
#include "mojo/public/cpp/bindings/associated_interface_request.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/lib/clone_equals_util.h"
#include "mojo/public/cpp/bindings/lib/control_message_handler.h"
#include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"
#include "mojo/public/cpp/bindings/lib/union_accessor.h"
#include "mojo/public/cpp/bindings/native_struct.h"
#include "mojo/public/cpp/bindings/no_interface.h"
#include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h"
#include "mojo/public/cpp/bindings/union_traits.h"
#include "net/base/network_change_notifier.h"
#include "net/url_request/redirect_info.h"
#include "services/service_manager/public/cpp/identity.h"
#include "services/service_manager/public/cpp/interface_provider_spec.h"
#include "services/service_manager/public/cpp/service_info.h"
#include "services/video_capture/public/cpp/capture_settings.h"
#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
#include "third_party/WebKit/public/web/WebPopupType.h"
#include "third_party/WebKit/public/web/WebWindowFeatures.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkImageFilter.h"
#include "ui/base/ime/composition_text.h"
#include "ui/base/ime/composition_underline.h"
#include "ui/base/ime/text_input_mode.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/base/window_open_disposition.h"
#include "ui/display/display.h"
#include "ui/events/event.h"
#include "ui/events/latency_info.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/icc_profile.h"
#include "ui/gfx/native_pixmap_handle.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/range/range.h"
#include "ui/gfx/range/range_f.h"
#include "ui/gfx/selection_bound.h"
#include "ui/gfx/transform.h"
#include "url/gurl.h"
#include "url/mojo/origin.mojom.h"
#include "url/origin.h"
#include <string>
#include <vector>

namespace mojom {
class MediaDevicesDispatcherHost;
using MediaDevicesDispatcherHostPtr = mojo::InterfacePtr<MediaDevicesDispatcherHost>;
using MediaDevicesDispatcherHostPtrInfo = mojo::InterfacePtrInfo<MediaDevicesDispatcherHost>;
using ThreadSafeMediaDevicesDispatcherHostPtr = mojo::ThreadSafeInterfacePtr<MediaDevicesDispatcherHost>;
using MediaDevicesDispatcherHostRequest = mojo::InterfaceRequest<MediaDevicesDispatcherHost>;
using MediaDevicesDispatcherHostAssociatedPtr = mojo::AssociatedInterfacePtr<MediaDevicesDispatcherHost>;
using ThreadSafeMediaDevicesDispatcherHostAssociatedPtr = mojo::ThreadSafeAssociatedInterfacePtr<MediaDevicesDispatcherHost>;
using MediaDevicesDispatcherHostAssociatedPtrInfo = mojo::AssociatedInterfacePtrInfo<MediaDevicesDispatcherHost>;
using MediaDevicesDispatcherHostAssociatedRequest = mojo::AssociatedInterfaceRequest<MediaDevicesDispatcherHost>;

class MediaDevicesListener;
using MediaDevicesListenerPtr = mojo::InterfacePtr<MediaDevicesListener>;
using MediaDevicesListenerPtrInfo = mojo::InterfacePtrInfo<MediaDevicesListener>;
using ThreadSafeMediaDevicesListenerPtr = mojo::ThreadSafeInterfacePtr<MediaDevicesListener>;
using MediaDevicesListenerRequest = mojo::InterfaceRequest<MediaDevicesListener>;
using MediaDevicesListenerAssociatedPtr = mojo::AssociatedInterfacePtr<MediaDevicesListener>;
using ThreadSafeMediaDevicesListenerAssociatedPtr = mojo::ThreadSafeAssociatedInterfacePtr<MediaDevicesListener>;
using MediaDevicesListenerAssociatedPtrInfo = mojo::AssociatedInterfacePtrInfo<MediaDevicesListener>;
using MediaDevicesListenerAssociatedRequest = mojo::AssociatedInterfaceRequest<MediaDevicesListener>;

using MediaDeviceInfo = mojo::NativeStruct;
using MediaDeviceInfoPtr = mojo::NativeStructPtr;

class MediaDevicesDispatcherHostProxy;

template <typename ImplRefTraits>
class MediaDevicesDispatcherHostStub;

class MediaDevicesDispatcherHostRequestValidator;
class MediaDevicesDispatcherHostResponseValidator;

class CONTENT_EXPORT MediaDevicesDispatcherHost
    : public MediaDevicesDispatcherHostInterfaceBase {
public:
    static const char Name_[];
    static constexpr uint32_t Version_ = 0;
    static constexpr bool PassesAssociatedKinds_ = false;
    static constexpr bool HasSyncMethods_ = false;

    using Proxy_ = MediaDevicesDispatcherHostProxy;

    template <typename ImplRefTraits>
    using Stub_ = MediaDevicesDispatcherHostStub<ImplRefTraits>;

    using RequestValidator_ = MediaDevicesDispatcherHostRequestValidator;
    using ResponseValidator_ = MediaDevicesDispatcherHostResponseValidator;
    enum MethodMinVersions : uint32_t {
        kEnumerateDevicesMinVersion = 0,
        kSubscribeDeviceChangeNotificationsMinVersion = 0,
        kUnsubscribeDeviceChangeNotificationsMinVersion = 0,
    };
    virtual ~MediaDevicesDispatcherHost() { }

    using EnumerateDevicesCallback = base::Callback<void(const std::vector<std::vector<::content::MediaDeviceInfo>>&)>;
    virtual void EnumerateDevices(bool request_audio_input, bool request_video_input, bool request_audio_output, const url::Origin& security_origin, const EnumerateDevicesCallback& callback) = 0;

    virtual void SubscribeDeviceChangeNotifications(::content::MediaDeviceType type, uint32_t subscription_id, const url::Origin& security_origin) = 0;

    virtual void UnsubscribeDeviceChangeNotifications(::content::MediaDeviceType type, uint32_t subscription_id) = 0;
};

class MediaDevicesListenerProxy;

template <typename ImplRefTraits>
class MediaDevicesListenerStub;

class MediaDevicesListenerRequestValidator;

class CONTENT_EXPORT MediaDevicesListener
    : public MediaDevicesListenerInterfaceBase {
public:
    static const char Name_[];
    static constexpr uint32_t Version_ = 0;
    static constexpr bool PassesAssociatedKinds_ = false;
    static constexpr bool HasSyncMethods_ = false;

    using Proxy_ = MediaDevicesListenerProxy;

    template <typename ImplRefTraits>
    using Stub_ = MediaDevicesListenerStub<ImplRefTraits>;

    using RequestValidator_ = MediaDevicesListenerRequestValidator;
    using ResponseValidator_ = mojo::PassThroughFilter;
    enum MethodMinVersions : uint32_t {
        kOnDevicesChangedMinVersion = 0,
    };
    virtual ~MediaDevicesListener() { }

    virtual void OnDevicesChanged(::content::MediaDeviceType type, uint32_t subscription_id, const std::vector<::content::MediaDeviceInfo>& device_infos) = 0;
};

class CONTENT_EXPORT MediaDevicesDispatcherHostProxy
    : public MediaDevicesDispatcherHost {
public:
    explicit MediaDevicesDispatcherHostProxy(mojo::MessageReceiverWithResponder* receiver);
    void EnumerateDevices(bool request_audio_input, bool request_video_input, bool request_audio_output, const url::Origin& security_origin, const EnumerateDevicesCallback& callback) override;
    void SubscribeDeviceChangeNotifications(::content::MediaDeviceType type, uint32_t subscription_id, const url::Origin& security_origin) override;
    void UnsubscribeDeviceChangeNotifications(::content::MediaDeviceType type, uint32_t subscription_id) override;

    void set_group_controller(
        scoped_refptr<mojo::AssociatedGroupController> group_controller)
    {
        group_controller_ = std::move(group_controller);
    }

private:
    mojo::MessageReceiverWithResponder* receiver_;
    scoped_refptr<mojo::AssociatedGroupController> group_controller_;
};

class CONTENT_EXPORT MediaDevicesListenerProxy
    : public MediaDevicesListener {
public:
    explicit MediaDevicesListenerProxy(mojo::MessageReceiverWithResponder* receiver);
    void OnDevicesChanged(::content::MediaDeviceType type, uint32_t subscription_id, const std::vector<::content::MediaDeviceInfo>& device_infos) override;

    void set_group_controller(
        scoped_refptr<mojo::AssociatedGroupController> group_controller)
    {
        group_controller_ = std::move(group_controller);
    }

private:
    mojo::MessageReceiverWithResponder* receiver_;
    scoped_refptr<mojo::AssociatedGroupController> group_controller_;
};
class CONTENT_EXPORT MediaDevicesDispatcherHostStubDispatch {
public:
    static bool Accept(MediaDevicesDispatcherHost* impl,
        mojo::internal::SerializationContext* context,
        mojo::Message* message);
    static bool AcceptWithResponder(MediaDevicesDispatcherHost* impl,
        mojo::internal::SerializationContext* context,
        mojo::Message* message,
        mojo::MessageReceiverWithStatus* responder);
};

template <typename ImplRefTraits = mojo::RawPtrImplRefTraits<MediaDevicesDispatcherHost>>
class MediaDevicesDispatcherHostStub
    : public NON_EXPORTED_BASE(mojo::MessageReceiverWithResponderStatus) {
public:
    using ImplPointerType = typename ImplRefTraits::PointerType;

    MediaDevicesDispatcherHostStub() { }
    ~MediaDevicesDispatcherHostStub() override { }

    void set_sink(ImplPointerType sink) { sink_ = std::move(sink); }
    ImplPointerType& sink() { return sink_; }

    mojo::internal::SerializationContext* serialization_context()
    {
        return &serialization_context_;
    }

    bool Accept(mojo::Message* message) override
    {
        if (ImplRefTraits::IsNull(sink_))
            return false;
        return MediaDevicesDispatcherHostStubDispatch::Accept(
            ImplRefTraits::GetRawPointer(&sink_), &serialization_context_, message);
    }

    bool AcceptWithResponder(
        mojo::Message* message,
        mojo::MessageReceiverWithStatus* responder) override
    {
        if (ImplRefTraits::IsNull(sink_))
            return false;
        return MediaDevicesDispatcherHostStubDispatch::AcceptWithResponder(
            ImplRefTraits::GetRawPointer(&sink_), &serialization_context_, message,
            responder);
    }

private:
    ImplPointerType sink_;
    mojo::internal::SerializationContext serialization_context_;
};
class CONTENT_EXPORT MediaDevicesListenerStubDispatch {
public:
    static bool Accept(MediaDevicesListener* impl,
        mojo::internal::SerializationContext* context,
        mojo::Message* message);
    static bool AcceptWithResponder(MediaDevicesListener* impl,
        mojo::internal::SerializationContext* context,
        mojo::Message* message,
        mojo::MessageReceiverWithStatus* responder);
};

template <typename ImplRefTraits = mojo::RawPtrImplRefTraits<MediaDevicesListener>>
class MediaDevicesListenerStub
    : public NON_EXPORTED_BASE(mojo::MessageReceiverWithResponderStatus) {
public:
    using ImplPointerType = typename ImplRefTraits::PointerType;

    MediaDevicesListenerStub() { }
    ~MediaDevicesListenerStub() override { }

    void set_sink(ImplPointerType sink) { sink_ = std::move(sink); }
    ImplPointerType& sink() { return sink_; }

    mojo::internal::SerializationContext* serialization_context()
    {
        return &serialization_context_;
    }

    bool Accept(mojo::Message* message) override
    {
        if (ImplRefTraits::IsNull(sink_))
            return false;
        return MediaDevicesListenerStubDispatch::Accept(
            ImplRefTraits::GetRawPointer(&sink_), &serialization_context_, message);
    }

    bool AcceptWithResponder(
        mojo::Message* message,
        mojo::MessageReceiverWithStatus* responder) override
    {
        if (ImplRefTraits::IsNull(sink_))
            return false;
        return MediaDevicesListenerStubDispatch::AcceptWithResponder(
            ImplRefTraits::GetRawPointer(&sink_), &serialization_context_, message,
            responder);
    }

private:
    ImplPointerType sink_;
    mojo::internal::SerializationContext serialization_context_;
};
class CONTENT_EXPORT MediaDevicesDispatcherHostRequestValidator : public NON_EXPORTED_BASE(mojo::MessageReceiver) {
public:
    bool Accept(mojo::Message* message) override;
};
class CONTENT_EXPORT MediaDevicesListenerRequestValidator : public NON_EXPORTED_BASE(mojo::MessageReceiver) {
public:
    bool Accept(mojo::Message* message) override;
};
class CONTENT_EXPORT MediaDevicesDispatcherHostResponseValidator : public NON_EXPORTED_BASE(mojo::MessageReceiver) {
public:
    bool Accept(mojo::Message* message) override;
};

} // namespace mojom

namespace mojo {

} // namespace mojo

#endif // CONTENT_COMMON_MEDIA_MEDIA_DEVICES_MOJOM_H_